$package('YY.main');

YY.main = function(){
	return {
		treeSelect:function(){
			var _this = $(this);
			var title=_this.text();
			var url=_this.attr('href');
			YY.main.addTab(title,url);
			return false;
		},
		treeInit:function(){
			var  $items =  $('#tree-box').find(".menu-item");
			$items.bind('click',this.treeSelect);
		},
		addTab:function(_title,_url){
			var boxId = '#tab-box';
			if($(boxId).tabs('exists',_title) ){
				var tab = $(boxId).tabs('getTab',_title);
				var index = $(boxId).tabs('getTabIndex',tab);
				$(boxId).tabs('select',index);
				if(tab && tab.find('iframe').length > 0){  
					var _refresh_ifram = tab.find('iframe')[0];  
					_refresh_ifram.contentWindow.location.href=_url;  
				} 
			}else{		
				var _content ="<iframe scrolling='auto' frameborder='0' src='"+_url+"' style='width:100%; height:100%'></iframe>";
				$(boxId).tabs('add',{
					title:_title,
					content:_content,
					closable:true});

			}
		},
		menuHover:function(){
			//菜单鼠标进入效果
			$('.menu-item').hover(
					function () {
						$(this).stop().animate({ paddingLeft: "25px" }, 200,function(){
							$(this).addClass("orange");
						});
					}, 
					function () {
						$(this).stop().animate({ paddingLeft: "15px" },function(){
							$(this).removeClass("orange");
						});
					}
			);
		},
		modifyPwd:function(){
			var pwdForm = $("#pwdForm");
			if(pwdForm.form('validate')){
				var parentId =$('#search_parentId').val();
				$("#edit_parentId").val(parentId)
				YY.saveForm(pwdForm,function(data){
					$('#modify-pwd-win').dialog('close');
					pwdForm.resetForm();
				});
			}
		},
		init:function(){
			this.treeInit();
			this.menuHover();

			//修改密码绑定事件
			$('.modify-pwd-btn').click(function(){
				$('#modify-pwd-win').dialog('open');
			});
			$('#btn-pwd-close').click(function(){
				$('#modify-pwd-win').dialog('close');
			});
			$('#btn-pwd-submit').click(this.modifyPwd);

		}
	};
}();

$(function(){
	YY.main.init();
});	
//外层弹出框1
function openFirstWin(url, title, width, height) {
	var strWidth;
	var strHeight;
	if (width == null)
		strWidth = 800;
	else
		strWidth = width;
	if (height == null)
		strHeight = 500;
	else
		strHeight = height;
	if (url != null) {
		var content = '<iframe name=\"first\" scrolling=\"auto\" frameborder=\"0\" src=\"' + url + '\" style=\"width:100%\;height:100%\;\"></iframe>';
//		var content = createIFrame(url);
		parent.$('#div_info').window({
			close: false,
			modal: true,
			draggable: false,
			title: title,
			animate: true,
			content: content,
			minimizable: false,
			width: strWidth,
			height: strHeight,
			top: (parent.$(parent.window).height() - height) * 0.5,
			left: (parent.$(window).width() + 200 - strWidth) * 0.5
		});
	}
	return false;
}
